package com.caiheng.api.service.attendance.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.caiheng.api.dao.attendance.AttendanceGroupMapper;
import com.caiheng.api.entity.attendance.AttendanceGroup;
import com.caiheng.api.entity.attendance.AttendanceGroupUser;
import com.caiheng.api.entity.sys.SysUser;
import com.caiheng.api.entity.wxuser.User;
import com.caiheng.api.service.attendance.AttendanceGroupService;
import com.caiheng.api.service.base.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 考勤组Service业务层处理
 * @author ruoyi
 * @date 2022-09-19
 */
@Service
public class AttendanceGroupServiceImpl extends BaseServiceImpl<AttendanceGroupMapper, AttendanceGroup> implements AttendanceGroupService {

    @Resource
    private AttendanceGroupMapper attendanceGroupMapper;

    @Override
    public AttendanceGroup selectAttendanceGroupByUserId(AttendanceGroupUser groupUser) {
        AttendanceGroup group = null;
        if(groupUser.getGroupId() != null){
            group = attendanceGroupMapper.selectById(groupUser.getGroupId());
        }
        if(group == null){
            QueryWrapper<AttendanceGroup> qw = new QueryWrapper<>();
            qw.eq("property_id",groupUser.getPropertyId());
            qw.eq("is_default",1);
            qw.last("limit 1");
            group = attendanceGroupMapper.selectOne(qw);
        }
        return group;
    }

    @Override
    public List<AttendanceGroup> selectAttendanceGroupList(Map<String, Object> map) {
        return attendanceGroupMapper.selectAttendanceGroupList(map);
    }
}
